<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */

namespace App\Command;

use App\Constant\Database\FriendEnum;
use App\Model\Friend;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Psr\Container\ContainerInterface;

use function Hyperf\Config\config;

#[Command]
class ApplyOverdueCommand extends HyperfCommand
{
    public function __construct(protected ContainerInterface $container)
    {
        parent::__construct('Friend:applyOverdue');
    }

    public function configure()
    {
        parent::configure();
        $this->setDescription('Friend apply auto overdue.');
    }

    public function handle()
    {
        $count = Friend::query()
            ->where('type', FriendEnum::TYPE_APPLY)
            ->where('status', FriendEnum::STATUS_CHECK)
            ->whereNotIn('friend', array_keys(config('assistant')))
            ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-3 day')))
            ->update(['type' => FriendEnum::TYPE_VERIFY, 'status' => FriendEnum::STATUS_OVERDUE]);
        logInfo('friend_apply_overdue', $count);
        $this->info('Friend apply overdue success.');
    }
}
